package com.guomao;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class StringDemo {

    public static void main(String[] args) throws UnsupportedEncodingException {


//        System.out.println(123);


        String str1 = "hello";//字符串常量池 属于方法区的一部分

        String str2 = new String("hello");//堆区

//        System.out.println(str1 == str2);

        char[] ch = {'h', 'e', 'l', 'l', 'o'};

        String str3 = new String(ch);

        System.out.println(str3);

        System.out.println(str2 == str3);

        byte[] b = {65, 66, 67, 68, 69};
        String str4 = new String(b);
        System.out.println(str4);


        System.out.println(str1.length());
        System.out.println(str1.charAt(0));
        System.out.println(str1.indexOf("e"));

        System.out.println(str1.lastIndexOf("l"));

        System.out.println(str1.isEmpty());

        System.out.println(str1.contains("ll"));

        System.out.println(str1.startsWith("h"));
        System.out.println(str1.endsWith("p"));


        System.out.println(str1.equals("hello"));
        System.out.println(str1.equals("HELLO"));

        System.out.println(str1.equalsIgnoreCase("HELLO"));

        System.out.println("JAVASE".toLowerCase());

        System.out.println("javase".toUpperCase());

        System.out.println("  JAVA SE  ");
        System.out.println("  JAVA SE  ".trim());


        System.out.println("JAVASE JAVAME JAVAEE".replace("A", "D"));

        //包含指定索引的字符
        System.out.println("springboot".substring(6));

        //[start,end)
        System.out.println("springmvcframework".substring(5, 8));


        System.out.println("java".concat("spring"));


        int x = 100;
        System.out.println(x + 200);

        String s = String.valueOf(x);
        System.out.println(s + 200);

        int[] arr = {1, 2, 3, 4, 5};

//        String s1 = String.valueOf(arr);
//        System.out.println(s1);

        String string = Arrays.toString(arr);
        System.out.println(string);


//        System.out.println(Arrays.toString("中国,美国,俄国".split(",")));

//        String[] arr1 = "中国,美国,俄国".split(",");
        String[] arr1 = "中国.美国.俄国".split("\\.");//\.

        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr1[i]);
        }

        System.out.println(String.join(",", "2025", "05", "16"));

        String name = "Alice";
        int age = 25;
        String formatted = String.format("Name: %s, Age: %d", name, age);
        System.out.println(formatted);


        byte[] b1 = "中".getBytes("UTF-8");
        byte[] b2 = "中".getBytes("GBK");

        System.out.println(Arrays.toString(b1));
        System.out.println(Arrays.toString(b2));


    }
}
